package com.jianglin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jianglin.mapper.RepairMapper;
import com.jianglin.model.Repair;
import com.jianglin.model.Tongji;
import com.jianglin.service.IRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RepairServiceImpl implements IRepairService {

    @Autowired
    private RepairMapper repairMapper;
//    @Override
//    public PageInfo<Repair> findRepairAll(int page, int pagesize, Repair repair) {
//        PageHelper.startPage(page, pagesize);
//        List<Repair> list = repairMapper.queryRepairAll(repair);
//        return new PageInfo<>(list);
//    }

//    @Override
//    public PageInfo<Repair> findRepairAll(int page, int pagesize, Repair repair, boolean isAdmin) {
//        PageHelper.startPage(page, pagesize);
//        List<Repair> list = repairMapper.queryRepairAll(
//                repair.getOwnerId(),
//                isAdmin,
//                repair.getComId(),
//                repair.getStatus()
//        );
//        return new PageInfo<>(list);
//    }

    @Override
    public PageInfo<Repair> findRepairAll(int page, int pagesize, Repair repair, boolean isAdmin) {
        repair.setIsAdmin(isAdmin); // 设置isAdmin到对象
        PageHelper.startPage(page, pagesize);
        List<Repair> list = repairMapper.queryRepairAll(repair); // 传递对象
        return new PageInfo<>(list);
    }


//    @Override
//    public PageInfo<Repair> findRepairAll(int page, int pagesize, Repair repair) {
//        PageHelper.startPage(page, pagesize);
//        List<Repair> list = repairMapper.queryRepairAll(
//                repair.getOwnerId(),
//                isAdmin,
//                repair.getComId(),
//                repair.getStatus()
//        );
//        return new PageInfo<>(list);
//    }

//    @Override
//    public List<Repair> queryList() {
//        return repairMapper.queryRepairAll(null);
//    }
    @Override
    public List<Repair> queryList() {
        Repair repair = new Repair();
        repair.setIsAdmin(true); // 查询所有数据
        return repairMapper.queryRepairAll(repair);
    }

    @Override
    public int add(Repair repair) {
        return repairMapper.add(repair);
    }

    @Override
    public int delete(Long id) {
        return repairMapper.delete(id);
    }

    @Override
    public int updateData(Repair repair) {
        return repairMapper.updateData(repair);
    }

    @Override
    public Repair findById(Long id) {
        return repairMapper.findById(id);
    }

    @Override
    public List<Tongji> queryTongji() {
        return repairMapper.queryTongji();
    }
}
